package com.muse.openfeign.feign.server;

import java.util.List;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.muse.openfeign.dto.User;

/**
 * @description
 * @author: muse
 * @create: 2021-08-08 21:41
 **/
@FeignClient(name = "openfeign-producer")
public interface ProviderService {

    @GetMapping("/provider/hello")
    String hello();

    /**
     * 传递基本类型参数
     */
    @GetMapping("/provider/baseParam")
    String baseParam(@RequestParam("name") String name, @RequestParam("age") Integer age);

    /**
     * 传递基本类型参数——路径
     */
    @GetMapping("/provider/baseParamPath/{name}/{age}")
    String baseParamPath(@PathVariable("name") String name, @PathVariable("age") Integer age);

    /**
     * 传递对象类型参数
     */
    @PostMapping("/provider/objectParam")
    String objectParam(@RequestBody User user);

    /**
     * 传递数组类型参数,通过queryString方式传递，即：/provider/arrayParam?params=1&params=2
     */
    @GetMapping("/provider/arrayParam")
    String arrayParam(@RequestParam("params") String[] params);

    /**
     * 传递集合类型参数
     */
    @GetMapping("/provider/listParam")
    String listParam(@RequestParam("params") List<String> params);

    /**
     * 传递集合类型参数
     * http://localhost:8000/provider/responseObj?userId=111
     */
    @GetMapping("/provider/responseObj")
    User responseObj(@RequestParam("userId") String userId);

    /**
     * 测试OpenFeign默认1秒请求超时
     * http://localhost:8000/producer/timeoutDemo
     */
    @GetMapping("/provider/timeoutDemo")
    String timeoutDemo();

}

